package com.camemax.netty.nio;

import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;

/**
 * Buffer组件的【类型化】特性
 */
public class NIOTypedBuffer {
    public static void main(String[] args) {
        ByteBuffer buffer = ByteBuffer.allocate(1024);
        buffer.putInt(1);
        buffer.putChar('W');
        buffer.putShort((short) 2);
        buffer.putLong(10000L);
        buffer.putDouble(13.5555D);

        buffer.flip(); // 读写切换
        // 顺序读取
        System.out.println(buffer.getInt());
        System.out.println(buffer.getChar());
        System.out.println(buffer.getShort());
        System.out.println(buffer.getLong());
        System.out.println(buffer.getDouble());

        // 异常读取
    }
}
